<uieip type="page" value="login" debug="true" timeout="5000"></uieip>
<uieip type="reg" value="console"></uieip>
<!DOCTYPE html>
<html>

<head>
    <uieip type="file" value="inc" src="/yqwin/easyui/include.txt" cache="true" minute="1440"></uieip>
    <uieip type="file" value="css" src="/yqwin/css/yqwin.min" cache="false"></uieip>
    <uieip type="file" value="js" src="/yqwin/src/yqwin.min" cache="false"></uieip>
    <title>tree edit</title>
</head>

<body style="margin: 0;">
    <table style="border-spacing: 0px;">
        <tr>
            <td>
                <ul id="tt">
                </ul>        
            </td>
            <td>
                <ul id="tt_d">
                </ul> 
            </td>
        </tr>
    </table>
    
    <script>
        var dbname="yqbase";

        function form_load(){
            $(window).resize(function(){
                onresize();
            });
            onresize();

            $('#tt').yqTree("loadData");
        }

        function onresize(){
            var w = $(window).width()-4;
            var h = $(window).height()-4;
            $('#tt').yqTree("resize",{
                "width":w*0.5,
                "height":h
            });

            $('#tt_d').yqTree("resize",{
                "width":w*0.5,
                "height":h
            });
        }

        $(function(){
            $.yqDbList({ajaxUrl: "_db.html"}, 
                function (data) {     
                    if (data.error == 0) {
                        dbname=data.rows[0].name;
                        init_tree();
                    }else{
                        alert(data.info);
                    }
                });   
        })

        function init_tree() {
            $('#tt').yqTree({
                ajaxUrl: "/_db.html", //ajax地址
                dbname: dbname,   //数据库
                tbname: "ab_test_tree",       //表
                keyId: "sid",       //关键字段
                bindingKeyId: null,
                bindingValue: null,
                pKeyId: "pid",
                pKeyValue: null,

                loadDataType: 1,    //全局加载模式
                displayMember:"name",   
                loadData: false,

                menuType: 1,  //1-顶部菜单，2-右键菜单，3-顶部+右键  其他，无菜单

                overflowY: true,
                //width: 180,
                //height: 300,

                editMode: 2,   //1,2-弹出编辑模态窗体 
                editModeW: 600, //模态编辑器宽度 格式为 800（数字） 
                editModeH: 450, //模态编辑器高度 格式为 600（数字） 
                editModeNo: -1, //编辑模板

                beforeBindingTitle: function (titles,callback) {
                    //console.log("beforeBindingTitle",titles);
                    callback(titles);
                }, //标题绑定前
                afterBindingTitle: function () {
                    init_tree_d();

                }, //标题绑定后

                beforeSetdata: function (data, callback) {
                    //console.log("beforeSetdata", data);
                    callback(data)
                }, //绑定数据之前
                afterSetdata: function (data) {
                    //console.log("afterSetdata", data);
                }, //绑定数据之后

                editLinks: [ {
                    id: "clear",
                    text: "setBindingValue null",
                    iconCls: "icon-clear",
                }],
 
                btnAction: function (action, params,callback) {
                    if(action=="clear"){
                        $('#tt_d').yqTree("setBindingValue",null);
                        $('#tt_d').yqTree("clear");
                    }
                    else{
                        callback(true);
                    }      
                },

                uppActionState: function (s_node, callback) {     //操作节点状态处理接口
                    //console.log("uppActionState",s_node);
                    callback(true);
                },
                onClick: function (node) {     //节点点击
                    console.log("node-m",node);
                    if(node==null){
                        $('#tt_d').yqTree("setBindingValue",null);
                        $('#tt_d').yqTree("clear");
                    }else{
                        $('#tt_d').yqTree("setBindingValue",node.id);
                        $('#tt_d').yqTree("loadData");
                    }
                },
            });
        }


        function init_tree_d() {
            $('#tt_d').yqTree({
                ajaxUrl: "/_db.html", //ajax地址
                dbname: dbname,   //数据库
                tbname: "ab_test_tree_d",       //表
                keyId: "sid",       //关键字段
                bindingKeyId: "mid",
                bindingValue: null,
                pKeyId: "pid",
                pKeyValue: null,

                loadDataType: 1,    //全局加载模式
                displayMember:"name",   
                loadData: false,

                menuType: 3,  //1-顶部菜单，2-右键菜单，3-顶部+右键  其他，无菜单

                overflowY: true,
                //width: 180,
                //height: 300,

                editMode: 2,   //1,2-弹出编辑模态窗体 
                editModeW: 600, //模态编辑器宽度 格式为 800（数字） 
                editModeH: 450, //模态编辑器高度 格式为 600（数字） 
                editModeNo: -1, //编辑模板

                beforeBindingTitle: function (titles,callback) {
                    //console.log("beforeBindingTitle",titles);
                    callback(titles);
                }, //标题绑定前
                afterBindingTitle: function () {
                    form_load();
                }, //标题绑定后

                beforeSetdata: function (data, callback) {
                    //console.log("beforeSetdata", data);
                    callback(data)
                }, //绑定数据之前
                afterSetdata: function (data) {
                    //console.log("afterSetdata", data);
                }, //绑定数据之后
                uppActionState: function (s_node, callback) {     //操作节点状态处理接口
                    //console.log("uppActionState",s_node);
                    callback(true);
                },
            });
        }

        function check() {
            window.parent.$MidWin.yqFormMdi("menuwin", {
                id: "",
                title: 'menu',
                openmore: true,
                content: '<button onclick="addmenu();">menu</button><button onclick="addedit();">edir</button>',
                url: "edit.html",
                closable: true,
            })
        }

    </script>

 
</body>

</html>